<html>
<head><meta charset="utf-8"><title>viewing assembly of `async` functions · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html">viewing assembly of `async` functions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="189049609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189049609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189049609">(Feb 25 2020 at 19:01)</a>:</h4>
<p>Inspecting the assembly of an async function seems to... not work?</p>
<div class="codehilite"><pre><span></span><span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">moo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">i64</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">async</span><span class="w"> </span><span class="k">fn</span> <span class="nf">example</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="kt">u64</span><span class="p">,</span><span class="w"> </span><span class="p">()</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">moo</span><span class="p">()</span><span class="w"> </span><span class="p">};</span><span class="w"></span>

<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Err</span><span class="p">(())</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Ok</span><span class="p">(</span><span class="n">result</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u64</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span>playground::example:
    xorl    %eax, %eax
    retq
</pre></div>


<p>Am I doing something dumb?</p>



<a name="189049765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189049765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189049765">(Feb 25 2020 at 19:03)</a>:</h4>
<p>The actual async function body is in the <code>Generator::resume</code> method</p>



<a name="189049824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189049824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189049824">(Feb 25 2020 at 19:03)</a>:</h4>
<p>I may not be following your point, but that's the literal entire output of the assembly — those 3 lines.</p>



<a name="189049917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189049917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189049917">(Feb 25 2020 at 19:04)</a>:</h4>
<p>Oh, perhaps you are saying that  the <code>resume</code> body is being stripped out because it's not public?</p>



<a name="189055801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189055801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189055801">(Feb 25 2020 at 20:07)</a>:</h4>
<p>yeah it may be getting stripped out</p>



<a name="189056119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189056119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189056119">(Feb 25 2020 at 20:10)</a>:</h4>
<p>you can call <code>futures::executor::block_on(example())</code> to force it to be included</p>



<a name="189056205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189056205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189056205">(Feb 25 2020 at 20:11)</a>:</h4>
<p>it adds a lot of code though :/</p>



<a name="189061260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/viewing%20assembly%20of%20%60async%60%20functions/near/189061260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/viewing.20assembly.20of.20.60async.60.20functions.html#189061260">(Feb 25 2020 at 21:07)</a>:</h4>
<p>Yeah, and I can't put an <code>#[inline(never)]</code> on <code>Generator::resume</code> to separate it from the executor.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>